package org.dochandler.esfinge.guardian.authorizer;

import org.dochandler.config.DHConfig;
import org.dochandler.service.domain.SituationOfState;
import org.dochandler.service.domain.annotation.StateOfWar;
import org.dochandler.service.exception.InvalidPopulationOfSituationOfStateException;
import org.esfinge.guardian.authorizer.Authorizer;
import org.esfinge.guardian.context.AuthorizationContext;

public class StateOfWarAuthorizer implements Authorizer<StateOfWar> {

	@Override
	public Boolean authorize(AuthorizationContext context, StateOfWar stateOfWar) {
		
		SituationOfState ss = null;
		try {
			String ssKey = DHConfig.getString("situation_of_state");
			ss = (SituationOfState) context.getEnvironment().get(ssKey);
			
		} catch(ClassCastException e) {
			throw new InvalidPopulationOfSituationOfStateException("Invalid population of SituationOfState annotation. ", e);
		}
		
		if (SituationOfState.WAR == ss) {
			return true;
		}
		return false;
	}

}
